/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.inf.ufg.model;

import br.inf.ufg.factory.ConexaoFactoryMySql;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author umarley.faria
 */
public class IngressosDAO {
    
    
    
    private Connection con;
    private Statement stmt;
    private Statement stmtNavegar;
    private ResultSet rsNavegar;
    
    
    
    public IngressosDAO() throws ClassNotFoundException, SQLException{        
         
             con = ConexaoFactoryMySql.getConnection();
             stmt = con.createStatement();
             stmtNavegar = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
                     ResultSet.CONCUR_UPDATABLE );
             rsNavegar = stmtNavegar.executeQuery( "select * from ingressos" );        
    
    }
    
    
    public boolean salvarRegistro( Ingressos ingresso ) throws SQLException, Exception{
          
         // int cod = evento.getIdEvento();
          int codigo = ingresso.getCodigo();
          int serie = ingresso.getSerie();
          String area = ingresso.getArea();
          int evento = ingresso.getEvento();
          int isVendido = ingresso.getIsVendido();
          int local = ingresso.getLocal();
          String assento = ingresso.getAssento();
           
        
        try {
            stmt.executeUpdate( "INSERT INTO `ingressos` (`CODIGO`, `SERIE`, "
                    + "`AREA`, `EVENTO`, `IS_VENDIDO`, `LOCAL`, `ASSENTO`) "
                    + "VALUES ("+ codigo +", "+ serie +", '"+ area +"', "
                    + ""+ evento +", "+ isVendido +", "+ local +", "
                    + "'"+ assento +"');");
            rsNavegar = stmtNavegar.executeQuery( "select * from ingressos" );
            return true;
            
        } catch ( SQLException e) {
                 throw new Exception("Erro ao inserir dados. Tente novamente " + e.getMessage());                      
        }
          
      }
    
    
        public boolean vendaIngresso( int cod ) throws SQLException, Exception{
          
        
        
        try {
            stmt.executeUpdate( "UPDATE `ingressos` SET `IS_VENDIDO`= 1 WHERE  `CODIGO`= "+ cod );
            rsNavegar = stmtNavegar.executeQuery( "select * from ingressos" );
            return true;
            
        } catch ( SQLException e) {
                 throw new Exception("Erro ao atualizar dados. Tente novamente " + e.getMessage());                      
        }
          
      }
    
    
    
    
    
    
}
